#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    this->setFixedSize(this->size());
    ui->progressBar->hide();

    connect(ui->tb_getInputFileDialog, SIGNAL(clicked()), this, SLOT(updateInputLineEdit()));
    connect(ui->tb_getOutputFileDialog, SIGNAL(clicked()), this, SLOT(updateOutputLineEdit()));
    connect(ui->clb_convert, SIGNAL(clicked()), this, SLOT(convert()));
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::changeEvent(QEvent *e)
{
    QMainWindow::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
        ui->retranslateUi(this);
        break;
    default:
        break;
    }
}

void MainWindow::updateInputLineEdit()
{
    QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), tr("CHM file(*.chm)"));
    ui->le_inputFile->setText(fileName);
    converter.setInputFile(fileName);
}

void MainWindow::updateOutputLineEdit()
{
    QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"), tr("PDF file (*.pdf)"));
    ui->le_outputFile->setText(fileName);
    converter.setOutputFile(fileName);
}

void MainWindow::convert()
{
    ui->progressBar->show();
    converter.convert();
    ui->progressBar->hide();
}
